<template>
  <div class="app-container">
    <el-form :model="formData"
             label-width="120px"
             label-position="left">
      <el-form-item label="分类">
        <el-input v-model="formData.name">
        </el-input>
      </el-form-item>
    </el-form>
    <div class="submit-box">
      <el-button type="primary"
                 :loading="loading"
                 style="width: 200px;"
                 @click.native.prevent="doSubmit">提交</el-button>
    </div>
  </div>
</template>

<script>
import { create } from '@/api/category'
import { errorMsg, successMsg } from '@/utils/my'

export default {
  data () {
    return {
      loading: false,
      formData: {
        name: ''
      }
    }
  },

  methods: {
    doSubmit () {
      let that = this, d = that.formData;
      if (d.name.length <= 0) {
        return errorMsg('请输入分类名')
      }
      that.loading = true
      create(that.formData).then(res => {
        that.loading = false
        if (res.code != 20000) {
          return errorMsg(res.message)
        }
        successMsg(res.message)
        setTimeout(function () {
          that.$router.push({ path: '/admin/article/category/list' })
        }, 1500)
      })
    }
  }
}
</script>

<style>
.submit-box {
  height: 50px;
  line-height: 50px;
  text-align: center;
  padding-right: 20px;
}
</style>
